<?php
class indexController extends Web_Controller_Base
{
    //初始化控制器，相当于构造函数
    public function init()
    {
    }
    
    public function indexAction()
    {
        $pageSize     = Web_Config_Page::blogPageSize();
        $navSize      = Web_Config_Page::blogNavSize();
        $page         = $this->getParam('page', 1);
        $pid          = $this->getParam('pid',  -1);
        $cid          = $this->getParam('cid',  -1);
        $classID      = -1;
        $className    = '';
        try {
            $limit = Web_Model_Navigate::getLimit($page, $pageSize);
            if($cid >= 0){
                $article = Web_Model_Article::getListBySubClassID($cid, $limit['start'], $limit['limit']);
                $classURL = "/cid/{$cid}";
                $classID = $cid;
                $className = Web_Model_Class::getClassNameByID($cid);
            }else if($pid >= 0){
                $article = Web_Model_Article::getListByMainClassID($pid, $limit['start'], $limit['limit']);
                $classURL = "/pid/{$pid}";
                $classID = $pid;
                $className = Web_Model_Class::getClassNameByID($pid);
            }else{
                $article = Web_Model_Article::getListAll($limit['start'], $limit['limit']);
                $classURL = '';
            }
            $class   = Web_Model_Class::getAllClass();
            $pageNav = Web_Model_Navigate::getPageListBar($article['total'], $page, $pageSize, $navSize);
        }catch (Exception $e){
            exit('系统异常,稍后重试');
        }
        if($className){
        	$this->setData('title', $className);
        } else {
        	$this->setData('title', '首页');
        }
        $this->setData('articles', $article['data']);
        $this->setData('class', $class);
        $this->setData('classID', $classID);
        $this->setData('classURL', $classURL);
        $this->setData('pageNav', $pageNav);
        $this->setView('Blog/index.tpl');
    }
}